<?php
/************************************************************/
/*				index.php = fichier de routage				*/
/************************************************************/
	require_once('config/root.php');
	require(ROOT.'core/model.php');
	require(ROOT.'core/controller.php');
	require(ROOT.'errors/erreur404.php');

	if(session_id() == ""){
		session_start();
	}
	
		$params[0] = "";
		$params = explode('/',$_GET['p']);
		$controller = $params[0] != "" ? $params[0] : DEFAULT_CONTROLLER;

	$action = isset($params[1]) ? $params[1] : DEFAULT_ACTION;
	$action = isset($params[1]) && $params[1] != '' ? $params[1] : DEFAULT_ACTION;
	$controller.='Controller';
	if(file_exists('controllers/'.$controller.'.php')){
		require('controllers/'.$controller.'.php');
		$controller = new $controller();
			if(method_exists($controller, $action)){
				unset($params[0]); unset($params[1]);
				call_user_func_array(array($controller, $action), $params);
			}else {
				$controller = new erreur404();
				unset($params[0]); unset($params[1]);
				call_user_func_array(array($controller, 'index'), $params);
			}
	}else {
				$controller = new erreur404();
				unset($params[0]); unset($params[1]);
				call_user_func_array(array($controller, $action), $params);
	}
	
?>
